module NavigatorTabs
  
  def nav_tabs
    @nav_rtabs = []
    @nav_ltabs = []
    @nav_tabs = true
    yield
    @nav_tabs = false
    true
  end
  
  def modo(*args)
    if block_given?
      yield if args.include?(session[:modo_tabs])
    else
      session[:modo_tabs] = args.first
    end
  end
  
  def tab(*args)
    return unless @nav_tabs
    label = args.shift
    url = args.shift
    options = args.shift
    if !url || url.empty?
      url = {:controller => label.underscore}
    end
    tab = [label, url, options]
    if options && options[:align] == :right
      @nav_rtabs << tab
    else
      @nav_ltabs << tab
    end
  end

end

ActionController::Base.send :include, NavigatorTabs
